/*
 * @Date: 2024-11-18 14:58:38
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-11-18 14:58:38
 * @Description: 系统参数管理页面
 */
import { defAxios as request } from '@/utils/http';

export function useSystemApi() {
	return {
		/**
		 * 获取系统参数
		 * @returns Proxy
		 */
		getSysParams() {
			return request({
				url: '/sysParam/getSysName',
				method: 'get',
			});
		},
		/**
		 * 保存系统参数信息
		 * @param {Object} params 系统参数信息
		 * @returns Proxy
		 */
		saveSysParam (params) {
			return request({
				url: '/sysParam/saveSysParam',
				method: 'post',
				data: params,
			});
		},
		/**
		 * 根据参数编码获取参数的值
		 * @param {String} code
		 * @returns Proxy
		 */
		getParamByCode(paramCode) {
			return new Promise((resolve) => {
				request({
					url: '/sysParam/info',
					method: 'post',
					data: { code: paramCode }
				}).then(res => {
					const { code, data, msg } = res
					if (code === 200) {
						resolve(data[paramCode] || '')
					} else {
						console.error(msg)
						resolve('')
					}
				}).catch(err => {
					console.error(err)
					resolve('')
				});
			})
		},
		/**
		 * 获取系统参数详细信息通过系统编码
		 *
		 * @param {String|Number} dCode 系统参数编码
		 * @returns Proxy
		 */
		getSysParamDetail (dCode) {
			return request({
				url: '/sysParam/getSysParamDetail',
				method: 'post',
				params: { dCode },
			});
		},
		/**
		 * 更新系统参数缓存
		 * @param {Object} params 系统参数信息
		 * @returns Proxy
		 */
		refreshSysParamCache (params) {
			return request({
				url: '/sysParam/refreshSysParamCache',
				method: 'post',
				data: params,
			});
		},
		/**
		 * 获取licenseInfo
		 *
		 * @returns axios
		 */
		getLicenseInfo() {
			return request({
				url: '/home/licenseInfo',
				method: 'get'
			})
		}
	};
}
